<?php
class PesanNotifikasiController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column1', meaning
	 * using one-column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
		//	'rights',
		);
	}

	public function allowedActions() 
        { 
            return ''; 
        }

	
	/**
	 * Lists all models.
	 */
	public function actionCheck()
	{
            $userId = Yii::app()->user->id; //pegawai ID
            
            $criteria = new CDbCriteria;
            $criteria->limit = 10;
            $criteria->order = 'id_pesan_notifikasi DESC';
            
            $find = PesanNotifikasi::model()->findAllByAttributes(
                    array(
                        'id_pegawai' => $userId,
                        'status' => 0
                        ),
                    $criteria
                    );
            
            $result = array();
            foreach($find as $key=>$value)
            {
                $result['result'][$key]['id']         = $value->id_pesan_notifikasi;
                $result['result'][$key]['url']        = $value->url;
                $result['result'][$key]['status']     = $value->status;
                $result['result'][$key]['notifikasi'] = $value->notifikasi;
                $result['result'][$key]['created_date'] = $value->created_date;
            }
            
            $result['count'] = count($find);
            echo CJSON::encode($result);
            Yii::app()->end();
	}
        
        public function actionUpdate($id)
        {
            $pesan = PesanNotifikasi::model()->findByPk($id);
            $pesan->status  = 1;
            $pesan->save();
        }
        
	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer the ID of the model to be loaded
	 */
	public function loadModel($id)
	{
		$model=PesanNotifikasi::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

	
}
